﻿using Microsoft.EntityFrameworkCore;
using MyTask.Domain.Commands;
using MyTask.Domain.Commands.Handlers;
using MyTask.Domain.Queries;
using MyTask.Domain.Queries.Handlers;
using MyTask.Infrastructure.Context;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace MyTask.Test
{
   public  class TestUser
    {
        private static string  connectionString = "Data Source=DESKTOP-MIB8DI4\\SQLEXPRESS;Initial Catalog=MyTask;Integrated Security=true;";
        private DbContextOptions<MyTaskContext> options = new DbContextOptionsBuilder<MyTaskContext>()
            .UseSqlServer(connectionString)
            .Options;
        [Fact]
        public  void Test1()
        {
            MyTaskContext context = new MyTaskContext(options);
            UserInfoCommandHandler userInfoCommandHandler = new UserInfoCommandHandler(context);
            UserInfoCommand command = new UserInfoCommand();
            command.UserName = "q393813438";
            command.FirstName = "Di";
            command.LastName = "JI";
            command.Email = "33e32e32@qq.com";
            command.Password = "123456";
            Assert.True(userInfoCommandHandler.Register(command));
        }

        [Fact]
        public void Test2()
        {
            MyTaskContext context = new MyTaskContext(options);
            UserInfoQueryHandler userInfoQueryHandler = new UserInfoQueryHandler(context);
            GetUserInfoByUserNameQuery query = new GetUserInfoByUserNameQuery();
            query.UserName = "qiangxianghui";
            var result = userInfoQueryHandler.GetUserInfoByUserName(query);
            Assert.NotNull(result);
        }

       
    }
}
